#ifndef FOCUS_SEARCH_H
#define FOCUS_SEARCH_H

#include <QQueue>

#include "focus_action.h"

class FocusSearch
{
public:
	FocusSearch() : border(false), focusPos(0), maxFocus(0) {}
	virtual ~FocusSearch() = default;
	virtual FocusAction search(const QQueue<double>& focusValues) = 0;
	void setBorder(bool border) { this->border = border; }
	virtual void setMaxFocus(int focus) { maxFocus = focus; }
	void setFocusPos(int pos) { focusPos = pos; }

protected:
	bool border;
	int maxFocus;
	int focusPos;
};

class ClimbSearch: public FocusSearch
{
public:
	ClimbSearch();
	FocusAction search(const QQueue<double>& focusValues) override;

private:
	const bool initialDirection;
	bool direction;
	std::pair<double, int> maxSearchPos;
	const int init_step;
	int step;
	double maxFocusValue;
	double threshold;
	std::pair<int, int> focusRange;
	std::pair<int, int> searchRange;
	bool finished;
	int finishedCount;
	std::pair<double, double> focusValuesRange;
	bool isClimb;
	FocusAction::Action init_action;
};

class TraverseSearch: public FocusSearch {
public:
	TraverseSearch();
	void setMaxFocus(int focus) override;
	FocusAction search(const QQueue<double>& focusValues) override;

private:
	std::pair<double, int> maxSearchPos;
	const int init_step;
	int step;
	double maxFocusValue;
	double threshold;
	std::pair<int, int> focusRange;
	std::pair<int, int> searchRange;
	bool finished;
	int finishedCount;
	std::pair<double, double> focusValuesRange;
};

#endif

